<extend name="Public/index"/>

<block name="content">
    <a class="button tiny" href="<{:U('addTeacher')}>">添加老师信息</a>
    <button onclick="unSelect()" class="button tiny">反选</button>
    <button onclick="delLot()" class="button tiny">删除(批量)</button>


    <table id="teacherTb1">
        <thead>
        <tr>
            <th><input  onclick="selectAll(this)" type="checkbox"></th>
            <th>编号</th>
            <th>姓名</th>
            <th>密码</th>
            <th>手机</th>
            <th>邮箱</th>
            <th>最后登录ip</th>
            <th>修改</th>
        </tr>
        </thead>

        <tbody>
        <volist name="navs" id="nav">
            <tr id="row_<{$nav.teacher_id}>">
                <td><input class="slct" type="checkbox" value="<{$nav.teacher_id}>"></td>
                <td><{$nav.teacher_id}></td>
                <td><input name="tname" class="es" disabled type="text" value=<{$nav.tname}>></td>
                <td><input name="pwd" class="es" disabled type="text" value="<{$nav.pwd}>"></td>
                <td><input name="mtel" class="es" disabled style="width:4em;" type="text" value="<{$nav.mtel}>"></td>
                <td><input name="email" class="es" disabled style="width:4em;" type="text" value="<{$nav.email}>"></td>
                <td><input name="login_ip" class="es" disabled style="width:4em;" type="text" value="<{$nav.login_ip}>"></td>

                <td>
                    <button onclick="edit('row_<{$nav.teacher_id}>')" class="button tiny edit">编辑</button>
                    <button onclick="save('<{$nav.teacher_id}>')" style="display: none;" class="button tiny save">保存</button>
                </td>
            </tr>
        </volist>
        </tbody>
    </table>
    <{$page}>
    <script>
        //全选
        function selectAll(obj) {
            $('#teacherTb1 tbody .slct').prop('checked',$(obj).prop('checked'));
        }
        //反选
        function unSelect() {
            $('#teacherTb1 tbody .slct').map(function(){
                $(this).prop('checked',!$(this).prop('checked'));
            });
        }

        //批量删除
        function delLot() {
            if(!confirm('确定删除吗?')){
                return;
            }
            var ids = $('#teacherTb1 tbody .slct:checked').map(function () {
                $(this).parent().parent().remove();
                return $(this).val();
            });
            ids  = ids.get().join();
            console.log(ids);
            $.post('<{:U("doDelTeacher")}>',{ids:ids},function (data) {
                alert('删除成功');
            });
        }


        function edit(rowid) {
            $('#'+rowid+' .es').prop('disabled',false);
            $('#'+rowid+' .edit').hide();
            $('#'+rowid+' .save').show();
        }

        function save(id) {
            $('#row_'+id+' .es').prop('disabled',true);
            $('#row_'+id+' .edit').show();
            $('#row_'+id+' .save').hide();

            var data = {
                teacher_id:id,
                tname:$('#row_'+id+' [name=tname]').val(),
                pwd:  $('#row_'+id+' [name=pwd]').val(),
                mtel :  $('#row_'+id+' [name=mtel]').val(),
                email :  $('#row_'+id+' [name=email]').val(),

            }

            $.post('<{:U("doEditTeacher")}>',data,function (data) {

                if(data.error!==0){
                    alert('修改成功');
                }
            });

        }

    </script>

</block>